<template>
  <div>
    <el-card style="width: 300px;display: inline-block;height: 450px;">
      <el-table :data="gantas" highlight-current-row height="300px" @row-click="rowclick">
        <el-table-column label="杆塔编号" prop="gcode"></el-table-column>
      </el-table>

    </el-card>
    <el-card style="width: 800px;display: inline-block;text-align: center;height: 450px;">
    <el-form :model="zi" style="height: 350px;">
    <el-form-item label="杆塔编号" label-width="200px">
      <el-input v-model="gcode"  disabled style="width: 400px;"></el-input>
    </el-form-item>
    <el-form-item label="有无缺陷" label-width="200px">
      <el-select v-model="zi.type" style="width: 400px;" :disabled="zi.isxiaoque==1">
        <el-option  v-for="item in hasAndno" :label="item.lable" :value="item.value" :key="item.value"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="缺陷类型" label-width="200px" >
      <el-select v-model="zi.quexianid" style="width: 300px;" :disabled="zi.isxiaoque==1">
      <el-option v-for="item in quexian" :label="item.qxtype" :value="item.qid" :key="item.qid">

      </el-option>
      </el-select>
      <el-button @click="addQue">添加缺陷</el-button>
    </el-form-item>
    <el-form-item label="发现人员" label-width="200px">
      <el-input  style="width: 400px;" v-model="$store.state.user.uname" :disabled="zi.isxiaoque==1"></el-input>
    </el-form-item>
    <el-form-item label="缺陷级别" label-width="200px">
    <el-select v-model="zi.error" style="width: 400px;" :disabled="zi.isxiaoque==1">
      <el-option v-for="item in error" :label="item.label" :value="item.value" :key="item.value"></el-option>
    </el-select>
    </el-form-item>
    <el-form-item label="缺陷描述" label-width="200px">
      <el-input :disabled="zi.isxiaoque==1" v-model="zi.miaoshu" style="width: 400px;" type="textarea"></el-input>
    </el-form-item>
    <el-form-item style="margin-top: -19px;">
      <el-button @click="baocun" >保存</el-button>
      <el-button @click="chongzhi">重置</el-button>
    </el-form-item>
    </el-form>
    </el-card>
    <el-card style="height: 70px;">
      <el-button @click="shangchuan">上传回执</el-button>
      <el-button @click="fanhui">返回</el-button>
    </el-card>
    <el-dialog title="添加缺陷类型" :visible.sync="dialogFormVisible" width="40%" style="text-align: center;">
      <el-form>
        <el-form-item label="缺陷类型名称:">
          <el-input v-model="form1.qxtype" style="width: 200px;"></el-input>
        </el-form-item>
        <el-form-item label="状态:">
          <el-radio :label="1" v-model="form1.isstatus">启用</el-radio>
          <el-radio :label="0" v-model="form1.isstatus">不启用</el-radio>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button type="primary" @click="addxz()">确 定</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">返回</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import axios from 'axios'
  export default{
    data(){
      return{
      xunjian:[],
      gantas:[],
      zi:{},
      hasAndno:[{
        value:'有',
        lable:'有'
      },
      {
        value:'无',
        lable:'无'
      }],
      quexian:[],
      error:[{
        value:'一般',
        label:'一般'
      },
      {
        value:'紧急',
        label:'紧急'
      },
      {
        value:'严重',
        label:'严重'
      }],
      gcode:'',
      dialogFormVisible:false,
      form1: {
        qid: '',
        qxtype: '',

        isstatus: 1
      },
      arr:[]
      }
    },
    methods:{
    getGantas:function(){
     let postData=this.$qs.stringify({
      zhuid:this.xunjian.id,
      uid:this.$store.state.user.uid,
      xid:this.xunjian.xid
     })
     axios.post("http:localhost:8086/zi/selectgantasByxunjian",postData).then(vs=>{
       this.gantas=vs.data
     })
    },
    getQuexian:function(){
    axios.post("http:localhost:8086/quexian/allByxunjian").then(vs=>{
      this.quexian=vs.data
      console.log(this.quexian)
    })
    },
    rowclick:function(row){
      this.gcode=row.gcode
      console.log(this.xunjian.id)
      let postData=this.$qs.stringify({
        uid:this.$store.state.user.uid,
        gantaid:row.gid,
        zhuid:this.xunjian.id
      })
      axios.post("http:localhost:8086/zi/huizhiselect",postData).then(vs=>{
        this.zi=vs.data
      })
    },
    addQue:function(){
      this.dialogFormVisible=true

    },
    addxz: function() {

      axios.post("http:localhost:8086/quexian/add", this.form1).then(vs => {
        if (vs.status = 200) {
          if (vs.data) {
            this.$message('添加成功')
            this.getQuexian()
            this.dialogFormVisible = false
            this.form1={}
            this.form1.isstatus=1

          } else {
            this.$message('添加失败已有该缺陷类型')
          }
        }
      })
    },
    baocun:function(){
      if(this.gcode==null||this.gcode==''){
        this.$message("请选择杆塔之后再保存")
        return
      }else if(this.zi.isxiaoque==1){
        this.$message("杆塔已经巡检，请不要重复保存")
        return
      }

      this.zi.xunjiarenwuzhu={}
      this.zi.xunjiarenwuzhu.id=this.xunjian.id
      axios.post("http:localhost:8086/zi/addZi",this.zi).then(vs=>{
        if(vs.status==200){
          this.$message("上传成功")
          this.zi={}
        }
      })
      console.log(this.zi)
    },
    chongzhi:function(){
      this.gcode=''
      this.zi={}
    },
    fanhui:function(){
      this.$router.push({path:'/zhidinghuizhi'})
    },
    shangchuan:function(){
    this.arr.forEach(item=>{
      if(item.isxiaoque!=1){
       item.isxiaoque=1
       item.type='无'
       item.xunjiarenwuzhu={}
       item.xunjiarenwuzhu.id=this.xunjian.id
       axios.post('http:localhost:8086/zi/updateZiWu',item).then(vs=>{
      if(vs.status==200){

      }else{
        this.$message('上传失败')
        return
      }
       }).catch(err=>{

       })
      }
    })
    this.$router.push({path:'/zhidinghuizhi'})
    }
    },
    created() {
    this.xunjian=this.$route.query
    console.log(this.xunjian)
    this.getGantas()
    this.getQuexian()
    let postData=this.$qs.stringify({
    uid:this.$store.state.user.uid,
    zhuid:this.xunjian.id
    })
    axios.post("http:localhost:8086/zi/selectAllziByuidAndZhuid",postData).then(vs=>{
    this.arr=vs.data
    })
    }
  }
</script>

<style>
</style>
